package com.yzyz.web.controller.visitor;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.yzyz.bean.scenic.ScenicBean;
import com.yzyz.service.ScenicService;

/**
 * 
 * @author David Sun
 * @Date   2010-4-14
 *
 */
public class SearchScenicController extends AbstractController {
	
	private ScenicService scenicService;
	
	public void setScenicService(ScenicService scenicService) {
		this.scenicService = scenicService;
	}

	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		String keyWords = request.getParameter("keyWords");
		List<ScenicBean> scenics = this.scenicService.search(keyWords);
		ModelAndView mv = null;
		if(scenics != null && scenics.size() != 0){
			ScenicBean scenic = scenics.get(0);
			mv = new ModelAndView("/scenic.htm?method=getInfoById&scenicId=" + scenic.getId());
			mv.addObject("searchResult", scenics);
		} else {
			mv = new ModelAndView("/Error/error.jsp");
			mv.addObject("errorMsg", "对不起！没有搜索到 " + keyWords + " 的相关信息");
		}
		return mv;
	}

}
